package com.feeyo.groundservice.recordnfc.base

import com.feeyo.groundservice.base_util.FyLog
import com.feeyo.groundservice.base_util.toastCenter
import com.feeyo.groundservice.composewidget.view.refreshlayout.RefreshContentStateEnum
import com.feeyo.groundservice.composewidget.view.refreshlayout.RefreshLayoutState
import com.feeyo.groundservice.http.base.BaseObserver


/**
 *作者：70893 on 2025-03-26
 *描述：
 */

var refreshState: RefreshLayoutState? = null

internal open class MyBaseObserver<T>(
    private val msg: String? = null,
    private val silence: Boolean = false,
    private val composeLoading: (Boolean) -> Unit = {},
) : BaseObserver<T>(msg, silence, composeLoading) {


    override fun onSuccess(data: T?) {
        finishRefreshCompose(true)
    }

    override fun onError(code: Int, msg: String) {
        super.onError(code, msg)
        toastCenter(msg)
        finishRefreshCompose(true)
    }


    //针对compose框架的刷新
    private fun finishRefreshCompose(success: Boolean) {
        refreshState?.let {
            FyLog.e("finishRefreshCompose", "finishRefreshCompose")
            if (success) {
                it.setRefreshState(RefreshContentStateEnum.Stop)
            } else {
                it.setRefreshState(RefreshContentStateEnum.Stop)
            }
        }
        refreshState = null
    }


}